###FIRST RUN Study 2 Data Code.R###

####APPENDIX TABLE 6####
atable6 <- matrix(NA,21,3)

atable6[1,1:3] <- as.vector(unlist(t.test(study2_mi$MALE[!is.na(study2_mi$PROP1_SQ) & study2_mi$PROP1_TREAT==1],study2_mi$MALE[!is.na(study2_mi$PROP1_SQ) & study2_mi$PROP1_TREAT==0])[c(5,3)]))
atable6[2,1:3] <- as.vector(unlist(t.test(study2_mi$AGE[!is.na(study2_mi$PROP1_SQ) & study2_mi$PROP1_TREAT==1],study2_mi$AGE[!is.na(study2_mi$PROP1_SQ) & study2_mi$PROP1_TREAT==0])[c(5,3)]))
atable6[3,1:3] <- as.vector(unlist(t.test(study2_mi$EDUCATION[!is.na(study2_mi$PROP1_SQ) & study2_mi$PROP1_TREAT==1],study2_mi$EDUCATION[!is.na(study2_mi$PROP1_SQ) & study2_mi$PROP1_TREAT==0])[c(5,3)]))
atable6[4,1:3] <- as.vector(unlist(t.test(study2_mi$INCOME[!is.na(study2_mi$PROP1_SQ) & study2_mi$PROP1_TREAT==1],study2_mi$INCOME[!is.na(study2_mi$PROP1_SQ) & study2_mi$PROP1_TREAT==0])[c(5,3)]))
atable6[5,1:3] <- as.vector(unlist(t.test(study2_mi$LIBCON[!is.na(study2_mi$PROP1_SQ) & study2_mi$PROP1_TREAT==1],study2_mi$LIBCON[!is.na(study2_mi$PROP1_SQ) & study2_mi$PROP1_TREAT==0])[c(5,3)]))
atable6[6,1:3] <- as.vector(unlist(t.test(study2_mi$RISK[!is.na(study2_mi$PROP1_SQ) & study2_mi$PROP1_TREAT==1],study2_mi$RISK[!is.na(study2_mi$PROP1_SQ) & study2_mi$PROP1_TREAT==0])[c(5,3)]))
atable6[7,1:3] <- as.vector(unlist(t.test(study2_mi$INFORMED1[!is.na(study2_mi$PROP1_SQ) & study2_mi$PROP1_TREAT==1],study2_mi$INFORMED1[!is.na(study2_mi$PROP1_SQ) & study2_mi$PROP1_TREAT==0])[c(5,3)]))
atable6[8,1:3] <- as.vector(unlist(t.test(study2_mi$INFORMED2[!is.na(study2_mi$PROP1_SQ) & study2_mi$PROP1_TREAT==1],study2_mi$INFORMED2[!is.na(study2_mi$PROP1_SQ) & study2_mi$PROP1_TREAT==0])[c(5,3)]))
atable6[9,1:3] <- as.vector(unlist(t.test(study2_mi$INFORMED3[!is.na(study2_mi$PROP1_SQ) & study2_mi$PROP1_TREAT==1],study2_mi$INFORMED3[!is.na(study2_mi$PROP1_SQ) & study2_mi$PROP1_TREAT==0])[c(5,3)]))
atable6[10,1:3] <- as.vector(unlist(t.test(study2_mi$INFORMED4[!is.na(study2_mi$PROP1_SQ) & study2_mi$PROP1_TREAT==1],study2_mi$INFORMED4[!is.na(study2_mi$PROP1_SQ) & study2_mi$PROP1_TREAT==0])[c(5,3)]))
atable6[11,1:3] <- as.vector(unlist(t.test(study2_mi$INFORMED5[!is.na(study2_mi$PROP1_SQ) & study2_mi$PROP1_TREAT==1],study2_mi$INFORMED5[!is.na(study2_mi$PROP1_SQ) & study2_mi$PROP1_TREAT==0])[c(5,3)]))
atable6[12,1:3] <- as.vector(unlist(t.test(study2_mi$INFORMED6[!is.na(study2_mi$PROP1_SQ) & study2_mi$PROP1_TREAT==1],study2_mi$INFORMED6[!is.na(study2_mi$PROP1_SQ) & study2_mi$PROP1_TREAT==0])[c(5,3)]))
atable6[13,1:3] <- as.vector(unlist(t.test(study2_mi$IMPORT1[!is.na(study2_mi$PROP1_SQ) & study2_mi$PROP1_TREAT==1],study2_mi$IMPORT1[!is.na(study2_mi$PROP1_SQ) & study2_mi$PROP1_TREAT==0])[c(5,3)]))
atable6[14,1:3] <- as.vector(unlist(t.test(study2_mi$IMPORT2[!is.na(study2_mi$PROP1_SQ) & study2_mi$PROP1_TREAT==1],study2_mi$IMPORT2[!is.na(study2_mi$PROP1_SQ) & study2_mi$PROP1_TREAT==0])[c(5,3)]))
atable6[15,1:3] <- as.vector(unlist(t.test(study2_mi$IMPORT3[!is.na(study2_mi$PROP1_SQ) & study2_mi$PROP1_TREAT==1],study2_mi$IMPORT3[!is.na(study2_mi$PROP1_SQ) & study2_mi$PROP1_TREAT==0])[c(5,3)]))
atable6[16,1:3] <- as.vector(unlist(t.test(study2_mi$IMPORT4[!is.na(study2_mi$PROP1_SQ) & study2_mi$PROP1_TREAT==1],study2_mi$IMPORT4[!is.na(study2_mi$PROP1_SQ) & study2_mi$PROP1_TREAT==0])[c(5,3)]))
atable6[17,1:3] <- as.vector(unlist(t.test(study2_mi$IMPORT5[!is.na(study2_mi$PROP1_SQ) & study2_mi$PROP1_TREAT==1],study2_mi$IMPORT5[!is.na(study2_mi$PROP1_SQ) & study2_mi$PROP1_TREAT==0])[c(5,3)]))
atable6[18,1:3] <- as.vector(unlist(t.test(study2_mi$IMPORT6[!is.na(study2_mi$PROP1_SQ) & study2_mi$PROP1_TREAT==1],study2_mi$IMPORT6[!is.na(study2_mi$PROP1_SQ) & study2_mi$PROP1_TREAT==0])[c(5,3)]))
atable6[19,1:3] <- as.vector(unlist(t.test(study2_mi$BLACK[!is.na(study2_mi$PROP1_SQ) & study2_mi$PROP1_TREAT==1],study2_mi$BLACK[!is.na(study2_mi$PROP1_SQ) & study2_mi$PROP1_TREAT==0])[c(5,3)]))
atable6[20,1:3] <- as.vector(unlist(t.test(study2_mi$HISP[!is.na(study2_mi$PROP1_SQ) & study2_mi$PROP1_TREAT==1],study2_mi$HISP[!is.na(study2_mi$PROP1_SQ) & study2_mi$PROP1_TREAT==0])[c(5,3)]))
atable6[21,1:3] <- as.vector(unlist(t.test(study2_mi$WHITE[!is.na(study2_mi$PROP1_SQ) & study2_mi$PROP1_TREAT==1],study2_mi$WHITE[!is.na(study2_mi$PROP1_SQ) & study2_mi$PROP1_TREAT==0])[c(5,3)]))
########################
